Migrate from subprocess upsc to PyNUTClient library#39
Open
houllette wants to merge 2 commits intohardwarehaven:mainfrom
Open
Migrate from subprocess upsc to PyNUTClient library#39houllette wants to merge 2 commits intohardwarehaven:mainfrom
houllette wants to merge 2 commits intohardwarehaven:mainfrom
Conversation
Author
|
This PR addresses #4 - @hardwarehaven would you be willing to take a look at this and consider merging? Happy to make any changes necessary! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrate from subprocess
upscto PyNUTClient libraryOverview
This PR refactors the UPS monitoring system to use the native Python
PyNUTClientlibrary instead of subprocess calls to theupsccommand. This provides more reliable communication with NUT servers, better error handling, and eliminates the externalupscdependency.Additionally addresses #4
Changes
Core Functionality
wolnut/monitor.py: Refactoredget_ups_status()to usePyNUTClient.GetUPSVars()instead of subprocesssubprocessimport foris_client_online()ping functionalitywolnut/config.py: Enhanced UPS identifier parsingparse_ups_identifier()function supporting multiple formats:"myups"→ connects to localhost:3493"myups@nut-server"→ connects to nut-server:3493"myups@nut-server:9999"→ custom porthostfield toNutConfigdataclass (default: "localhost")host/portconfig fields override parsed valueswolnut/cli.py: Updatedget_ups_status()calls to pass fullNutConfigobjectDependencies
pyproject.toml: AddedPyNUTClient>=2.8.4dependencyTests
tests/test_monitor.py: New comprehensive test suite (16+ tests)tests/test_config.py: Added 17 new testsTestParseUpsIdentifier: 10 tests for UPS identifier parsingTestLoadConfigWithParsing: 7 tests for config loading with parsingDocumentation
README.md: Updated to reflect PyNUTClient usageconfig.example.yaml: Added comprehensive comments explaining UPS format options and optional fieldsBackward Compatibility
✅ Fully backward compatible - all existing configurations continue to work:
ups: "myups@localhost"→ parsed toups="myups",host="localhost"ups: "myups@server:3493"→ parsed with custom portTesting
Benefits
upscprocess requiredMigration Notes
No action required for existing users - all current configurations work as-is. Optional: Users can now specify
hostandportas separate fields for clarity.Files Changed
pyproject.tomlwolnut/config.pywolnut/monitor.pywolnut/cli.pytests/test_monitor.pytests/test_config.pyREADME.mdconfig.example.yamlTotal: ~545 lines added/modified